package com.example.xgakj.mvp_demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.allen.library.SuperButton;
import com.allen.library.SuperTextView;
import com.example.xgakj.mvp_demo.event.LoginEvent;
import com.example.xgakj.mvp_demo.utils.ToastUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.tv_info)
    TextView tvInfo;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.stv_test)
    SuperTextView stvTest;
    @BindView(R.id.sbtn_ok)
    SuperButton sbtnOk;
    int anInt=1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(LoginEvent event) {
        Toast.makeText(this, event.getMessage(), Toast.LENGTH_SHORT).show();
    }

    ;

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

    @OnClick(R.id.btn_login)
    public void onViewClicked() {
//        Retrofit retrofit = new Retrofit.Builder()
//                .baseUrl("http://www.kuaidi100.com/")
//                .client(RetrofitUtil.getOkHttpClient()) // 打印请求参数
//                .addConverterFactory(GsonConverterFactory.create())
//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // 支持RxJava
//
//                .build();
//
//        RetrofitService service = retrofit.create(RetrofitService.class);
//        Observable<PostInfo> observable = service.getPostInfo("yuantong", "11111111111");
//        observable.subscribeOn(Schedulers.io()) // 在子线程中进行Http访问
//                .observeOn(AndroidSchedulers.mainThread()) // UI线程处理返回接口
//                .subscribe(new Observer<PostInfo>() { // 订阅
//                    @Override
//                    public void onError(Throwable e) {
//
//                    }
//
//                    @Override
//                    public void onComplete() {
//
//                    }
//
//                    @Override
//                    public void onSubscribe(Disposable d) {
//
//                    }
//
//                    @Override
//                    public void onNext(PostInfo postInfo) {
////                        Log.i("http返回：", postInfo.toString() + "");
//                        tvInfo.setText(postInfo.toString());
//                    }
//                });

    }

    @OnClick(R.id.sbtn_ok)
    public void onViewClicked2() {
        ToastUtil.showToast("超级按钮"+anInt);
    }

}
